/*
clsquare - closed loop simulation system
Copyright (c) 2004, Neuroinformatics Group, Prof. Dr. Martin Riedmiller,
University of Osnabrueck

Author: Roland Hafner

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

   * Redistributions of source code must retain the above copyright
     notice, this list of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above copyright
     notice, this list of conditions and the following disclaimer in
     the documentation and/or other materials provided with the
     distribution.
   * Neither the name of the <ORGANIZATION> nor the names of its
     contributors may be used to endorse or promote products derived
     from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE. 
*/

#ifndef _INPUT_H_
#define _INPUT_H_

#include "setdef.h"
#include "interpol_lin_fun.h"
#include <vector>

  /** This class computes initial states for an episode 
      Two modes are currently implemented: random states and states from file. */
class Input{
 public:
  /** sets initial state of episode.
   * \param initial_state : initial state of episode
   * \return true for success */
  bool get_initial_state(double* initial_state);

  /**  get the input of reference value for plant.
   * \param reference_input: reference input for the plant
   * \param cycle_ctr: control cycle in current episode */
  bool get_reference_input(double* reference_input, long cycle_ctr);

  /** initializes input module.
   * \param state_dim: dimension of state space
   * \param action_dim: dimension of action space
   * \param reference_input_dim: dimension of reference input
   * \param delta_t: duration of a control cycle [s]
   * \param fname: file which contains configuration of input module 
   * \return true for success */
  bool init(const int state_dim, const int action_dim, const int _reference_input_dim, const double _delta_t, const char *fname=0);

  /** does nothing */
  bool deinit(); //terminate


 protected:
  /** level of detail of log-outputs. */
  int verbosity;

   /** dimension of state space. */
  int state_dim;

  /** dimension of action space. */
  int action_dim;

  /** dimension of reference input **/
  int reference_input_dim;

  /** duration of one control cycle [s]. */
  float delta_t;
  
  /** modee of choosing initial states and target states. */
  int input_mode;
  
  /** counts episodes. */
  long int episode_counter;

  /** defines subset of state space, from which random states are chosen from */
  SetDef input_set;

  /** order of presentation of states from file.
   * \li 0: serial
   * \li 1 random */   
  int order_of_presentation; 

  /** current index of starting state. */
  int  act_stup_id;

  /** list of initial states from file. */
  std::vector< std::vector<double> > stups;

  /*** list of reference inputs. */
  std::vector< InterpolLinFun1D* > ref_inp_fun;


  /** parses initial states from file. */
  bool parse_input_file(const char *fname);
 
  /** gets a randomly chosen initial state from the input set.
   * \param state: initial state */   
  void get_state_mode0(double* initial_state);

  /** gets an initial state chosen from a list of states (file)
   * \param state: initial state */
  void get_state_mode1(double* initial_state);
  
  /** reads configuration of input module. 
   * \param fname: filename
   * \return true for success */
  bool read_options(const char * fname);

  double *distortion_vec;

  
};



#endif

